package kr.hkit.powerjava.chapter22.submit;

import java.util.ArrayList;

public class StudentManager implements DaoInterface<Student> { //인터페이스구현
	private ArrayList<Student> arList;

	public StudentManager() {
		arList = new ArrayList<>();
	}

	public StudentManager(ArrayList<Student> arList) {
		this.arList = arList;
	}
	
	
	public void prnList(){ //출력
		prnHeader();			
		for(Student std : arList) { //arList에서 한개씩 꺼내서 출력
			System.out.println(std);
		}
	}
	
	public void prnHeader() {
		String header = String.format("%3s\t%4s\t%4s\t%4s\t%4s\t%4s\t%5s","학번","성명","국어","영어","수학","총점","평균");
		System.out.println(header);
	}

	@Override
	public void addItem(Student item) {
		arList.add(item);		
	}

	@Override
	public Student searchItem(Student item) {
		if (arList.contains(item)) {
			return arList.get(arList.indexOf(item));
		} else {
			return null;
		}		
	}

	@Override
	public void updateItem(Student item) {
		arList.set(arList.indexOf(item), item);
		//위에 꺼 쓰든 이거 쓰든 둘다 가능 
		/*Student temp = arList.get(arList.indexOf(item)); //인덱스찾아내서
		temp.setStdNum(item.getStdNum());
		temp.setStdName(item.getStdName());
		temp.setKorScore(item.getKorScore());
		temp.setEngScore(item.getEngScore());
		temp.setMathScore(item.getMathScore());		*/
	}

	@Override
	public void delItem(Student item) {
		if (arList.contains(item)) {
			arList.remove(arList.indexOf(item)); //참조주소 삭제 
		}else {
			System.out.println("해당 학생 정보가 없습니다.");
		}		
	}
}	
